package com.xiaoma.lock.condition.reponsitory;

public class TestDemo {

  public static void main(String[] args) {
    //新建一个容量为100的仓库
    Repository repository = new Repository(100);


    //模拟生产者，每隔1000毫秒生产23个产品
    new Thread(new Runnable() {
      public void run() {
        while (true) {
          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          repository.produce(23);
        }
      }
    }, "producer1").start();


    //模拟消费者1，每隔2500毫秒消费产品25
    new Thread(new Runnable() {
      public void run() {
        while (true) {
          try {
            Thread.sleep(2500);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }

          repository.consume(25);
        }
      }
    }, "consumer1").start();

    //模拟消费者2，每隔1500毫秒消费产品10
    new Thread(new Runnable() {
      public void run() {
        while (true) {
          try {
            Thread.sleep(1500);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }

          repository.consume(10);
        }

      }
    }, "consumer2").start();
  }
}
